# -*- coding: utf-8 -*-

import re

from trac.core import *
from trac.env import IEnvironmentSetupParticipant

class MailFilterSetup(Component):
    
    implements(IEnvironmentSetupParticipant)
    
    # IEnvironmentSetupParticipant methods
    def environment_created(self):
        self.found_db_version = 0
        self.upgrade_environment(self.env.get_db_cnx())

    def environment_needs_upgrade(self, db):
        # Check for our custom fields
        if 'mail_id' not in self.config['ticket-custom']:
            return True
            
        # Fall through
        return False

    def upgrade_environment(self, db):
        custom = self.config['ticket-custom']
        if 'mail_id' not in custom:
            custom.set('mail_id', 'text')
            custom.set('mail_id.label', 'Mail ID')
            self.config.save()
            
